package com.chain.BrotherExchange.utils;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

public class ViewUtils {

    public static void notEditable(EditText editText) {
        editText.setFocusable(false);
        editText.setKeyListener(null);
    }

    public static void setTextAndSelectionEnd(TextView textView, EditText editText) {
        setTextAndSelectionEnd(textView.getText().toString(), editText);
    }

    public static void setTextAndSelectionEnd(String string, EditText editText) {
        if (!TextUtils.isEmpty(string)) {
            editText.setText(string);
            editText.setSelection(string.length());
        } else {
            editText.setText(string);
        }
    }

    public static void setMargins (View v, int l, int t, int r, int b) {
        if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
            p.setMargins(l, t, r, b);
            v.requestLayout();
        }
    }
}
